SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE dbo.[DnnProduct_Journal_DeleteByGroupId]
@PortalId int,
@GroupId int 
AS
DELETE dbo.[DnnProduct_Journal_Security] 
FROM dbo.[DnnProduct_Journal_Security] as js  INNER JOIN dbo.[DnnProduct_Journal] as j 
   ON js.JournalId = j.JournalId
WHERE j.PortalId = @PortalId AND j.GroupId = @GroupId AND @GroupId > 0 AND j.GroupId IS NOT NULL

DELETE dbo.[DnnProduct_Journal_Comments] 
FROM dbo.[DnnProduct_Journal_Comments] as jc  INNER JOIN dbo.[DnnProduct_Journal] as j 
   ON jc.JournalId = j.JournalId
WHERE j.PortalId = @PortalId AND j.GroupId = @GroupId AND @GroupId > 0 AND j.GroupId IS NOT NULL

DELETE FROM dbo.[DnnProduct_Journal] WHERE PortalId = @PortalId AND GroupId = @GroupId AND @GroupId > 0 AND GroupId IS NOT NULL



GO
